<div class="full-screen">
    <header>
    <div class="a-bar">
        <a href="<{link app=b2c ctl=wap_gallery act=cat}>" class="a-back">
            <i class="arr left"></i>
            商品分类
        </a>
        <div class="a-name">
            所有商品
        </div>
        <div class="a-right">
            <div class="a-search"></div>
        </div>
    </div>
    </header>
    <div class="pt-gallery">
        <div class="tab J-tab">
            <ul class="trigger-list">
                <li class="trigger act">
                    默认
                </li>
                <li class="trigger price-seq">
                    价格
                    <i class="arr down"></i>
                </li>
                <li class="trigger sales-seq">
                    销量
                    <i class="arr down"></i>
                </li>
            </ul>
            <ul class="panel-list">
                <li class="panel act"><{include file='wap/gallery/type/list.html'}></li>
                <li class="panel"></li>
                <li class="panel"></li>
            </ul>
        </div>
    </div>
</div>
<script>
    (function(){
        var priceSeq = 'price desc';
        var salesSeq = 'buy_w_count desc';
        var url = '<{link app=b2c ctl=wap_gallery act=ajax_get_goods}>';
        var page = '<{$page}>';
        var brand_id = '<{$brand_data.brand_id}>';
        // var filter_dialog;

        function filterGoods(t,e){
            var filter = '',
                sear = '',
                p = '',
                search = location.search;
            if( e&&$('.trigger-list .act').hasClass('price-seq') )filter = '&orderBy=' + priceSeq;
            if( e&&$('.trigger-list .act').hasClass('sales-seq') )filter = '&orderBy=' + salesSeq;
            if( t.hasClass('price-seq') ){
                filter = '&orderBy=' + priceSeq;
                if(priceSeq == 'price desc'){
                    priceSeq = 'price asc';
                    t.find('i')[0].className = 'arr down';
                }else{
                    priceSeq = 'price desc';
                    t.find('i')[0].className = 'arr top';
                }
            }
            if( t.hasClass('sales-seq') ){
                filter = '&orderBy=' + salesSeq;
                salesSeq = salesSeq == 'buy_w_count desc' ? 'buy_w_count asc' : 'buy_w_count desc';
            }
            if( e&&e.num ){
                p = '&page='+e.num;
                page = e.num;
            }
            if( search )sear = search.substr(1);
            $.post(url,'brand_id='+brand_id+filter+p+'&showtype=list&'+sear,function(re){
                $($('.J-tab .panel')[t.index()]).html(re);
            });
        }

        $('.J-tab .trigger').on('tap',function(){
            filterGoods( $(this) );
        });
        $('.filter-handle').on('tap',function(){
            filter_dialog = new Dialog('#filter_container');
        });
        $('.panel-list').on('click',function(e){
            var t = $(e.target);
            if(t.hasClass('flip')){
                t.num = parseInt(t.attr('page'));
                if(t.hasClass('next'))t.num = parseInt(page)+1;
                if(t.hasClass('prev'))t.num = parseInt(page)-1;
                filterGoods($('.trigger-list .act'),t);
                return false;
            }
        }).on('change','select',function(){
            var t = $(this.options[this.selectedIndex]);
            if(t.hasClass('flip')){
                t.num = parseInt(t.attr('page'));
                filterGoods($('.trigger-list .act'),t);
            }
        });

    })();
</script>
